<?php
namespace app\organize\home;

use app\common\controller\Common;
use app\organize\model\department as DepartmentModel;
use think\Request;

class Department extends Common
{
    public function getDepartmentList()
    {
    	$depart_data = DepartmentModel::getDepartmentList();
    	header("Access-Control-Allow-Origin: *");
		header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization");
    	return json_encode($depart_data);
    }

    public function getStaffList()
    {
        // if ($this->request->isPost()) {
        //     $data = $this->request->post();
        //     // 验证
        //     $result = $this->validate($data, 'AdminUser');
        //     if($result !== true) {
        //         return $this->error($result);
        //     }
        // }
        $request = Request::instance();
        $param = $request->param();
    	$current_depart_id = isset($param['depart_id'])?$param['depart_id']:1;
    	$keywords = isset($param['keywords'])?$param['keywords']:'';
    	$page = isset($param['page'])?$param['page']:1;
    	$pageSize = isset($param['limit'])?$param['limit']:10;
    	$user_ret = DepartmentModel::getUserByDepartId($current_depart_id ,$keywords, $page, $pageSize);
    	header("Access-Control-Allow-Origin: *");
		header("Access-Control-Allow-Headers: Content-Type, X-Requested-With, Cache-Control,Authorization");
    	return json_encode(['code'=>0,'msg'=>'','count'=>$user_ret['count'],'data'=>$user_ret['data']]);
    }
}